﻿using System.IO;

namespace Grinder.Renamer
{
    static class ExtensionMethods
    {
        public static string GetNameWithoutExtension(this FileSystemInfo file)
        {
            int i = file.Name.LastIndexOf('.');

            return (i == -1) ? file.Name : file.Name.Substring(0, i);
        }
        
        public static string Format(this int num, int digits)
        {
            int counterLength = num.ToString().Length;
            int diff = digits - counterLength;
            string formatted = num.ToString();

            if (diff > 0)
            {
                for (int i = 0; i < diff; i++)
                    formatted = "0" + formatted;
            }

            return formatted;
        }
    }
}
